#include <avr/io.h>
#include <stdio.h>
#include "netstack.h"
#include "uart.h"
#include <util/delay.h>
#include "smartprintf.h"
#include <avr/pgmspace.h>

#define BAUD 57600
#include <util/setbaud.h>

//static FILE mystdout = FDEV_SETUP_STREAM(send, NULL, _FDEV_SETUP_WRITE);
const char newline[] PROGMEM = "\n\r";
int main(void)
{

	

		//config uart
	UBRRH = UBRRH_VALUE;
	UBRRL = UBRRL_VALUE;

	#if USE_2X
		UCSRA |= (1 << U2X);
	#else
		UCSRA &= ~(1 << U2X);
	#endif

	UCSRB = (1 << RXEN) | (1 << TXEN) | (1 << RXCIE);
	UCSRC = (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1);

	uint8_t c;
	
	int testint = 54770;
	smartprintf("\n\rsmartprintf test ", testint );
    
/*	const char* addr = newline;
	while (c = pgm_read_byte (addr++), c != '\0')
	{
		smartprintf("%c", c);
	}

*/	smartprintf("test\n\r");

//	stdout = &mystdout;
	
	net_init();	
	net_handle();



	while(1)
	{
		net_handle();
		_delay_ms(500);
	}
}
